#!/bin/bash

#version
version="1.0.0"

run_do_contro()
{   
    DISK_TYPE=$1
}

run_do_contro_address()
{   
    CON_ADDR=$1
}

run_do_replica_level()
{   
    REPLICA_LEVEL=$1
}

run_do_type_property()
{
    CACHE_TYPE=$1
}

run_do_first_disk()
{   
    FRIST_DISK=$1
}

run_do_second_disk()
{   
    SECOND_DISK=$1
}

run_do_third_disk()
{   
    THIRD_DISK=$1
}

run_do_build_client()
{   
    BUILD_CLIENT=$1
}

run_do_build_server()
{
    BUILD_SERVER=$1
}

run_do_data_size()
{
    DATA_SIZE=$1
}



ARGS=`getopt -o '' --long version,cache-type: -- "$@"`
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
eval set -- "$ARGS"
while true;do
    case "$1" in
         --contro-type)
            #echo "--contro-type"
            run_do_contro $2
            shift 2
            ;;
         --contro-addr)
            #echo "--contro-addr"
            run_do_contro_address $2
            shift 2
            ;;
         --replica-level)
            #echo "--replica-level"
            run_do_replica_level $2
            shift 2
            ;;
         --cache-type)
            #echo "--cache-type"
            run_do_type_property $2
            shift 2
            ;;
         --first-disk)
            #echo "--first-disk"
            run_do_first_disk $2
            shift 2
            ;;
         --second-disk)
            #echo "--second-disk"
            run_do_second_disk $2
            shift 2
            ;;
         --third-disk)
            #echo "--third-disk"
            run_do_third_disk $2
            shift 2
            ;;
         --build-client)
            #echo "--build-client"
            run_do_build_client $2
            shift 2
            ;;
         --build-server)
            #echo "--build-server"
            run_do_build_server $2
            shift 2
            ;;
         --data-size)
            #echo "--data-size"
            run_do_data_size $2
            shift 2
            ;;
          --version)
            echo "$version"
            shift
            ;;
        --)
            shift
            break
            ;;
        *) 
            echo "未知的属性:{$1}"
            exit 1
            ;;
    esac
done


if [ $DISK_TYPE="bottom" ];then
# bottom disk config
r_level=$REPLICA_LEVEL
f_disk=$FRIST_DISK
s_disk=$FRIST_DISK
c_addr=$CON_ADDR
./cli/r_cli $r_level $f_disk $s_disk $c_addr
elif [ $DISK_TYPE="logical" ];then
# logical disk config
c_type=$CACHE_TYPE
f_disk=$FRIST_DISK
s_disk=$FRIST_DISK
t_disk=$THIRD_DISK
d_size=$DATA_SIZE
./cli/l_cli $c_type $f_disk $s_disk $t_disk $d_size
else
echo "Please use the correct parameters"
fi

if [ $BUILD_CLIENT="yes" ];then
./build/init-client.sh
elif [ $BUILD_server="yes" ];then
./build/init-server.sh
fi
